# -*- coding: utf-8 -*-
"""
Created on Tue Dec  2 11:10:37 2020
pytest 227_fixtureandreport.py
-v --html=".\\myreports\\result.html"
@author: andrew
"""

# pytest
import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


# @pytest.fixture(scope="function",autouse=True)
@pytest.fixture(scope="class", autouse=True)
def all_beginning(request):
    """setup-teardown"""
    # microseconds
    starttime = time.time()*10e6
    # print("starting time:",starttime)
    driver = webdriver.Chrome('./diver/chromedriver')
    # request参数不能少，可以将driver传递到该函数的范围之外，instance和cls都可以
    # request.instance.driver = driver
    request.cls.driver = driver
    yield
    endtime = time.time()*10e6
    elapsedtime = endtime - starttime
    print("elapsed time:", elapsedtime)
    driver.close()


# @pytest.mark.usefixtures("all_beginning")
class Testdemo:
    def test_test1(self):
        self.driver.get("https://www.baidu.com/")
        self.driver.set_window_size(1290, 690)
        elem = self.driver.find_element_by_name("wd")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        time.sleep(1)

    def test_test2(self):
        self.driver.get("https://docs.pytest.org/")
        self.driver.set_window_size(990, 690)
        time.sleep(1)
